<template>
  <div id="app">
    <div class="container">
      <div class="close">
        <span class="iconfont iconicon-test"></span>
      </div>
      <div class="logo">
        <span class="iconfont iconnew"></span>
      </div>
      <div class="inputs">
        <myipt
          placeholder="请输入手机号"
          :rules="/^(\d{5,6})$|^(1\d{10})$/"
          msg="用户名或者手机号输入不正确"
          class="input"
          v-model="user.username"
          @statu="loginnn"
        ></myipt>
        <myipt
          placeholder="密码"
          :rules="/^\S{3,16}$/"
          msg="请输入3-16位的密码"
          class="input"
          type="password"
          v-model="user.password"
          @statu="loginn"
        ></myipt>
      </div>
      <p class="tips">
        没有账号？
        <a href="#/register" class>去注册</a>
      </p>
      <btn class="button" @click="login">登录</btn>
    </div>
  </div>
</template>

<script>
import btn from "@/components/btn";
import myipt from "@/components/myinput";
import { mylogin } from "@/api/user";
export default {
  components: {
    btn,
    myipt,
  },
  data() {
    return {
      uStatu: true,
      pStatu: true,
      statu: true,
      user: {
        username: "10086",
        password: "123",
      },
    };
  },
  methods: {
    loginn(data) {
      this.pStatu = data;
    },
    loginnn(data) {
      this.uStatu = data;
    },
    //   接口类型:【POST】
    // 接口地址:login
    async login() {
      this.statu = this.uStatu && this.pStatu;
      if (this.statu) {
        // myaxios
        //   .post("/login", this.user)
        let res = await mylogin(this.user);
        // console.log(res);
        // console.log(data);
        if (res.data.statusCode == 401) {
          // Toast(data.data.message);
          this.$toast.fail(res.data.message);
        } else {
          this.$toast.success(res.data.message);
          localStorage.setItem("vueToken", res.data.data.token);
          this.$router.push({
            name: "personal",
            params: { id: res.data.data.user.id },
          });
        }
      } else {
        this.$toast.fail("检查输入信息");
      }
    },
  },
};
</script>

<style lang="less" scoped>
.container {
  padding: 20px;
}

.close {
  span {
    font-size: 27 / 360 * 100vw;
  }
}

.logo {
  display: flex;
  justify-content: center;

  span {
    display: block;
    font-size: 126 / 360 * 100vw;
    color: #d81e06;
  }
}

.inputs {
  input {
    margin-bottom: 20px;
  }
}

.tips {
  text-align: right;
  margin-bottom: 20px;

  a {
    color: #3385ff;
  }
}
</style>